/**
 * 记录当前高亮输入框和键盘
 * 控制点击其他区域，让输入框和键盘失去焦点
 */
let $activeInput;
let $activeKeyBoard;
let hadCheckedBlur = null;
/**
 * 重置数据
 */
const resetState = () => {
    window.__$VUEBOARDINPUT_activeInput = $activeInput = null;
    window.__$VUEBOARDINPUT_activeKeyboard = $activeKeyBoard = null;
    hadCheckedBlur = null;
    console.log("blur:resetState");
    console.trace();
};
/**
 *
 * @param {*} obj
 *  - dom
 *  - vm
 */
export const setCurrInput = function(obj) {
    window.__$VUEBOARDINPUT_activeInput = $activeInput = obj;
    if (process.env.NODE_ENV === "development") {
        console.warn("当前输入框=====：", obj);
    }
};
export const setCurrKeyBoard = function(obj) {
    window.__$VUEBOARDINPUT_activeKeyboard = $activeKeyBoard = obj;
    if (process.env.NODE_ENV === "development") {
        console.warn("当前键盘===", obj);
    }
};
export const getActiveInput = function() {
    return $activeInput ? $activeInput : {};
};
export const getActiveKeyBoard = function() {
    return $activeKeyBoard ? $activeKeyBoard : {};
};
const checkInputIsBlur = function(target) {
    let { dom, vm } = getActiveInput();
    let isBlur = !dom ?
        false :
        !(dom && typeof dom.contains == "function" && dom.contains(target));
    return { inputDom: dom, inputVm: vm, InputBlur: isBlur, vm };
};
const checkKeyBoardIsBlur = function(target) {
    let { dom, vm } = getActiveKeyBoard();
    let isBlur = !dom ?
        false :
        !(dom && typeof dom.contains == "function" && dom.contains(target));
    return { keyBoardDom: dom, keyBoardVm: vm, keyBoardBlur: isBlur, vm };
};
/**
 *
 */
export let $checkBlur = function(e) {
    let target = e.target;
    let input = checkInputIsBlur(target);
    let keyboard = checkKeyBoardIsBlur(target);
    if (input.InputBlur && keyboard.keyBoardBlur) {
        input.vm.mixins_triggerFocus(!input.InputBlur); //不做检测是否是函数，因为所有子组件都必须mixins它
        input.vm.unSelect ? input.vm.unSelect() : "";
        console.log("blur.js keyboard.vm", keyboard.vm);
        //不做检测是否是函数，因为所有子组件都必须mixins它
        keyboard.vm.mixins_triggerShow(!keyboard.keyBoardBlur);
        resetState();
    }
};
if (!hadCheckedBlur) {
    document.addEventListener("click", $checkBlur);
    hadCheckedBlur = true;
}